package com.example.email;


import org.apache.commons.mail.*;

public class EmailSender {
    private static void sendHtmlEmail(String to, String subject, String htmlContent, String textMessage) {
        String host = "smtp.qq.com";
        int port = 587;
        String username = "2243277448@qq.com";
        String password = "ylsgkyjdvnkcdiff";

        try {
            HtmlEmail email = new HtmlEmail();
            email.setHostName(host);
            email.setSmtpPort(port);
            email.setAuthenticator(new DefaultAuthenticator(username, password));
            email.setStartTLSEnabled(true);
            email.setFrom("2243277448@qq.com");
            email.setSubject(subject);
            email.addTo(to);
            email.setHtmlMsg(htmlContent);
            email.setTextMsg(textMessage);
            email.setCharset("UTF-8");

            email.send();
            System.out.println("HTML 邮件已发送至: " + to);

        } catch (EmailException e) {
            e.printStackTrace();
        }
    }

    public static void sendRefundSuccessNotification(String to, String orderId) {
        String subject = "退款成功通知 - 订单编号：" + orderId;
        String htmlMsg = "<div style='font-family: Arial, sans-serif; max-width: 600px; margin: auto; border: 1px solid #ddd; padding: 20px; border-radius: 8px;'>"
                + "<h2 style='color: #4CAF50;'>退款成功通知</h2>"
                + "<p>尊敬的乘客您好：</p>"
                + "<p>您的订单 <strong>" + orderId + "</strong> 已成功退款。</p>"
                + "<p>款项将尽快退回至您的原支付账户，请注意查收。</p>"
                + "<br>"
                + "<p style='color: #555;'>感谢您的理解与配合。</p>"
                + "<p><strong>花龙腾航客服团队</strong></p>"
                + "</div>";
        String textMsg = "订单 " + orderId + " 已退款成功，请注意查收原支付账户。";

        sendHtmlEmail(to, subject, htmlMsg, textMsg);
    }

    public static void sendDelayNotification(String to, String flightId) {
        String subject = "航班延误通知 - 航班编号：" + flightId;
        String htmlMsg = "<div style='font-family: Arial, sans-serif; max-width: 600px; margin: auto; border: 1px solid #ddd; padding: 20px; border-radius: 8px;'>"
                + "<h2 style='color: #e63946;'>航班延误通知</h2>"
                + "<p>尊敬的乘客您好：</p>"
                + "<p>您预订的航班 <strong>" + flightId + "</strong> 因特殊原因将延迟起飞。</p>"
                + "<p>请留意后续通知，我们将尽快安排新的航班时间。</p>"
                + "<br>"
                + "<p style='color: #555;'>感谢您的理解与配合。</p>"
                + "<p><strong>花龙腾航客服团队</strong></p>"
                + "</div>";
        String textMsg = "您预订的航班 " + flightId + " 已延误，请留意后续通知。";

        sendHtmlEmail(to, subject, htmlMsg, textMsg);
    }

    public static void sendFlightDeletedNotification(String to, String flightId) {
        String subject = "航班已取消通知 - 航班编号：" + flightId;
        String htmlMsg = "<div style='font-family: Arial, sans-serif; max-width: 600px; margin: auto; border: 1px solid #ddd; padding: 20px; border-radius: 8px;'>"
                + "<h2 style='color: #e63946;'>航班取消通知</h2>"
                + "<p>尊敬的乘客您好：</p>"
                + "<p>您预订的航班 <strong>" + flightId + "</strong> 已被取消。</p>"
                + "<p>如有疑问，请联系客服处理退款或改签事宜。</p>"
                + "<br>"
                + "<p style='color: #555;'>感谢您的理解与配合。</p>"
                + "<p><strong>花龙腾航客服团队</strong></p>"
                + "</div>";
        String textMsg = "您预订的航班 " + flightId + " 已被取消，请留意后续通知。";

        sendHtmlEmail(to, subject, htmlMsg, textMsg);
    }

    public static void sendFlightUpdatedNotification(String to, String flightId) {
        String subject = "航班信息已更新通知 - 航班编号：" + flightId;
        String htmlMsg = "<div style='font-family: Arial, sans-serif; max-width: 600px; margin: auto; border: 1px solid #ddd; padding: 20px; border-radius: 8px;'>"
                + "<h2 style='color: #457b9d;'>航班信息更新通知</h2>"
                + "<p>尊敬的乘客您好：</p>"
                + "<p>您预订的航班 <strong>" + flightId + "</strong> 的信息已更新。</p>"
                + "<p>请查看最新航班时间及其他相关信息。</p>"
                + "<br>"
                + "<p style='color: #555;'>感谢您的理解与配合。</p>"
                + "<p><strong>花龙腾航客服团队</strong></p>"
                + "</div>";
        String textMsg = "您预订的航班 " + flightId + " 的信息已更新，请查看最新航班时间及其他信息。";

        sendHtmlEmail(to, subject, htmlMsg, textMsg);
    }

    public static void main(String[] args) {
    }
}
